package cn.edu.dlmu.cogo.framework.web;

import cn.edu.dlmu.cogo.framework.annotation.Controller;
import cn.edu.dlmu.cogo.framework.annotation.RequestMapping;
import cn.edu.dlmu.cogo.framework.annotation.RequestParam;
import cn.edu.dlmu.cogo.framework.config.JavaConfig;
import cn.edu.dlmu.cogo.framework.config.WebConfig;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yixi
 */
@Controller
@RequestMapping("system")
public class SystemController {

    @RequestMapping("get-web-config")
    public ResponseBody getWebConfig(@RequestParam("username") String username,@RequestParam("password") String password){
        WebConfig webConfig = JavaConfig.getConfig(WebConfig.class);
        if (webConfig.getAdminUsername().equals(username) && webConfig.getAdminPassword().equals(password)){
            Map<String, Object> data = new HashMap<>(4);
            data.put("port",webConfig.getPort());
            data.put("root",webConfig.getRoot() == null ? "null" : webConfig.getRoot().getAbsolutePath());
            data.put("Apis",webConfig.getRequestBody().getMapping());
            return ResponseBody.success(data);
        }else {
            return ResponseBody.failure();
        }
    }
}
